package com.buaa.controller;

import com.buaa.annotation.CurrentUser;
import com.buaa.common.Result;
import com.buaa.dto.CurrentUserDTO;
import com.buaa.dto.UserExtensionDTO;
import com.buaa.service.impl.UserExtensionServiceImpl;
import com.buaa.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@Controller
@RequestMapping("/userext")
public class UserExtensionController {

    @Autowired
    private UserExtensionServiceImpl userExtensionServiceImpl;


    @Autowired
    private UserServiceImpl userServiceImpl;

    @PostMapping("/del/batch/")
    public Result deleteBatch(@RequestBody List<Integer> ids, HttpServletRequest request){
        return userExtensionServiceImpl.deletUserExtByIds(ids, request);
    }


    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id") Integer id, HttpServletRequest request){
        return userExtensionServiceImpl.deleteUserExtById(id, request);
    }

    @PutMapping("/save")
    public Result saveUserExtension(@RequestBody UserExtensionDTO userExtensionDTO, HttpServletRequest request, @CurrentUser CurrentUserDTO currentOpUser) {

        return userExtensionServiceImpl.saveUserExt(userExtensionDTO, request);

    }

    @GetMapping("/page")
    public Map<String,Object> findPage(@RequestParam String policeId, @RequestParam String userName, @RequestParam() Integer pageNum, @RequestParam Integer pageSize) {
        return userExtensionServiceImpl.findPageByPidAndUserName(policeId, userName, pageNum, pageSize);
    }

//   @GetMapping("/page2")
//   public List<UserExtensionDTO> findPage2(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
//       pageNum = (pageNum-1) * pageSize;
//       return userExtensionServiceImpl.findPage3(pageNum, pageSize);
//   }
//    public boolean save2(@RequestBody UserExtensionDTO userExtension) {
//        userExtensionServiceImpl.getUserExtensions2();
//        return true;

}
